var http = require("../../../utils/httpUtils.js")
var common = require("../../../utils/common.js")
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0, 
    selectPerson: true,
    exchangeCodeStatus:true,
    cash_coupon:[],
    exchange_coupon:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '我的优惠券',
    })
    this.getData();
  },
  couponBtn:function(){
    console.log(11111)
    wx.navigateBack({
      delta: 0
    })
  },
  getData:function(){
    http.G(app.globalData.SERVER_IP +'/user/cashCoupon/u_id/'+wx.getStorageSync('userInfo').userid+'/skip/0/limit/20',{},(res)=>{
      let informationData = res.result
      console.log(informationData)
      for(var i=0;i<informationData.length;i++){
        informationData[i].start = common.getTime(informationData[i].cc_start_time,".");
        informationData[i].end = common.getTime(informationData[i].cc_end_time,".");
      }
			this.setData({
        cash_coupon: informationData
      })
		},(err)=>{
			console.log("error:")
			console.log(err)
    })
    http.G(app.globalData.SERVER_IP +'/user/exchangeCoupon/u_id/'+wx.getStorageSync('userInfo').userid+'/skip/0/limit/20',{},(res)=>{
      let informationData = res.result
      console.log(informationData)
      for(var i=0;i<informationData.length;i++){
        informationData[i].start = common.getTime(informationData[i].ec_start_time,".");
        informationData[i].end = common.getTime(informationData[i].ec_end_time,".");
        if(informationData[i].ec_end_time<common.getTime()){
          informationData[i].out_of_time = 1
        }else{
          informationData[i].out_of_time = 0
        }
      }
			this.setData({
        exchange_coupon: informationData
      })
		},(err)=>{
			console.log("error:")
			console.log(err)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu({
		})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindchange: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  checkCurrent: function(e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  getExchangeCode:function(e){
    var temp= "exchange_coupon["+e.currentTarget.dataset.index+"].key"
    this.setData({
       [temp] : !this.data.exchange_coupon[e.currentTarget.dataset.index].key
    })
  }
})